package com.dove.controller;

import com.dove.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

        @Autowired
        @Qualifier("RestTemplate1")
        private RestTemplate restTemplate;

        //    private final static String REST_URL_PREFIX = "http://localhost:8001";
        private final static String REST_URL_PREFIX = "http://SPRING-PROVIDER-DEPT-8001";

        @RequestMapping("/dept/add")
        public boolean add(@RequestBody Dept dept){
            return restTemplate.postForObject(REST_URL_PREFIX +"/dept/add",dept,Boolean.class);
        }
        @RequestMapping("/dept/get/{id}")
        public Dept get(@PathVariable("id") Long id){
            return restTemplate.getForObject(REST_URL_PREFIX +"/dept/get/"+id,Dept.class);
        }
        @RequestMapping("/dept/list")
        public List<Dept> queryAll(){
            return restTemplate.getForObject(REST_URL_PREFIX +"/dept/list",List.class);
        }
}
